/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.gob.dirpen.dao.impl;

import java.util.List;
import org.apache.log4j.Logger;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import pe.gob.dirpen.dao.DependenciaDAO;
import pe.gob.dirpen.entities.GenmaDependencia;

/**
 *
 * @author Home
 */
@Repository
public class DependenciaDAOImpl extends HibernateDaoSupport implements DependenciaDAO {

    private static final Logger logger = Logger.getLogger(AnioDAOImpl.class);

    @Autowired
    public DependenciaDAOImpl(SessionFactory sessionFactory) {
        setHibernateTemplate(new HibernateTemplate(sessionFactory));
    }

    @Override
    public List<GenmaDependencia> buscarArea(GenmaDependencia dependencia) {
        DetachedCriteria criteria = DetachedCriteria.forClass(GenmaDependencia.class);
        return getHibernateTemplate().findByCriteria(criteria);
    }

    @Override
    public void registrarArea(GenmaDependencia dependencia) {
        this.getHibernateTemplate().saveOrUpdate(dependencia);
    }

    @Override
    public GenmaDependencia obtenerAreas(int dependencia) {
        Query query = getSession().createQuery(" from GenmaDependencia m where m.ndepeIdentificador = :id ").setInteger("id", dependencia);
        return (GenmaDependencia) query.uniqueResult();
    }
}
